package com.unrarme.api.morpher
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.xml.XMLNode;
	
	public class Morpher extends EventDispatcher
	{
		private var serviceUrl:String = 'http://morpher.ru/Webservices/Morpher.asmx/GetForms';
		public var data:Array = new Array();
		
		public function Morpher(word:String)
		{
			var request:URLRequest = new URLRequest(this.serviceUrl);
			request.method = URLRequestMethod.GET;
			var data:URLVariables = new URLVariables();
			data.s = word;
			request.data = data;
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(request);
		}
		
		private function onComplete(e:Event):void {
			var data:String = (e.target as URLLoader).data;
			var xml:XML = new XML(data);
			this.data = new Array();
			for each (var item:XML in xml.children()) {
				this.data.push(item.toString());
			}
			dispatchEvent(new Event(Event.COMPLETE));
			//trace(xml.ArrayOfString);
			//for each (var item:XML in list) {
//				trace('!' + item);
//			}
		}
		
		
		
	}
}